home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 4
/
The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO
/
clang
/
cujaug93.zip
/
1108110A
< prev
next >
Wrap
Text File
|
1993-06-09
|
683b
|
33 lines
/* arith.c: Illustrate pointer arithmetic */
#include <stdio.h>
#include <stddef.h>
main()
{
float a[] = {1.0, 2.0, 3.0};
float *p;
ptrdiff_t diff;
/* Increment a pointer */
printf("sizeof(float) == %u\n",sizeof(float));
p = &a[0];
printf("p == %p, *p == %f\n",p,*p);
++p;
printf("p == %p, *p == %f\n",p,*p);
/* Subtract two pointers */
diff = (p+1) - p;
printf("diff == %d\n",diff);
diff = (char *)(p+1) - (char *)p;
printf("diff == %ld\n",(long)diff);
return 0;
}
/* OUTPUT:
* sizeof(float) == 4
* p == FFEA, *p == 1.000000
* p == FFEE, *p == 2.000000
* diff == 1
* diff == 4 */